#include "MsgHandle.h"

msg_port_t network_msg_port;

uint8_t	check_send_state(void)
{
	return 1;
}

void msg_write(uint8_t *str,uint8_t size)
{
	send(SOCK_TCPS,str,size);			
}


void msg_params_init(void)
{
		init_msgport(&network_msg_port,check_send_state,msg_write);
}


void msg_recive(void)
{
	static uint8_t msg_buff[32];
	if(network_state.rec_len != 0 && network_state.network_state == SOCK_ESTABLISHED)
	{
		recv(SOCK_TCPS,msg_buff,network_state.rec_len);		
		ringBuff_enqueue(&network_msg_port.MsgRX_RingBuff,msg_buff,network_state.rec_len);
		network_state.rec_len = 0;
	}
}

void msg_handle(void)
{
	static uint8_t msg_size;
	static uint8_t msg_buff[32];

	if(ringBuff_noEmpty(&network_msg_port.MsgRX_RingBuff) == 1)
	{
		ringBuff_dequeue(&network_msg_port.MsgRX_RingBuff,msg_buff,&msg_size);
		log_out(&network_msg_port,msg_buff,msg_size);
	}

}

void msg_send(void)
{
	msg_port_handle(&network_msg_port);
}
